﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Manager_Dondathang_Controls_UC_ChitietDondathang : System.Web.UI.UserControl
{
    BUS_Order ord = new BUS_Order();
    BUS_OrderDetail ordDetail = new BUS_OrderDetail();
    BUS_Customers cus = new BUS_Customers();
    BUS_PayMethod pay = new BUS_PayMethod();
    BUS_Province pro = new BUS_Province();
    protected void Page_Load(object sender, EventArgs e)
    {
        LoadData();
        
    }
    public void LoadData()
    {
        

        string Id = Request.QueryString["id"];
        if (Id != null)
        {
            try
            {
                var dataOrder = ord.Order_GetByID(Id);

                txtSodondathang.Text = Id;
                txtTenkhachhang.Text = cus.Customers_GetByID(dataOrder.Rows[0]["Cus_Id"].ToString()).Rows[0]["UserName"].ToString();
                txtNgaydathang.Text = dataOrder.Rows[0]["Date"].ToString();
                txtPhuongthuc.Text = pay.PayMethod_GetByID(dataOrder.Rows[0]["PayMethod"].ToString()).Rows[0]["Name"].ToString();
                txtTennguoinhan.Text = dataOrder.Rows[0]["Cus_Name"].ToString();
                txtDiachinhan.Text = dataOrder.Rows[0]["Cus_Add"].ToString();
                txtTinhnhanhang.Text = pro.Province_GetByID(dataOrder.Rows[0]["Cus_Province"].ToString()).Rows[0]["Name"].ToString();
                txtSodienthoai.Text = dataOrder.Rows[0]["Cus_Phone"].ToString();

                rptDathang.DataSource = ordDetail.OrderDetail_GetByTop(0, "Order_Id = " + Id, "");
                rptDathang.DataBind();
                bool check = bool.Parse(dataOrder.Rows[0]["Finish"].ToString());
                if (check)
                {
                    lblTrangthai.Text = "Đã giao hàng";
                    btnXacnhan.Enabled = false;
                    btnXacnhan.Text = "Đã xác nhận";
                }
                lblTongtien.Text = string.Format("{0:0,0}", float.Parse(dataOrder.Rows[0]["TotalMoney"].ToString())) + " VND";
                ord.Order_UpdateBySet(Id, "[Check] = '1'");
            }
            catch
            {
                Panel1.Visible = false;
                Literal1.Text = "<p class='thongbao'>Trang này hiện không có.</p>";
            }
            
 
        }
        else
        {
            Response.Redirect("DonDatHang.aspx");
        }
        
        
    }
    public string TenSP(string id)
    {
        BUS_Product data = new BUS_Product();
        return data.Product_GetById(id).Rows[0]["Name"].ToString();
    }
    

    protected void btnXacnhan_Click(object sender, EventArgs e)
    {
        ord.Order_UpdateBySet(Request.QueryString["id"], "[Finish] = '1'");
        Response.Redirect(Request.RawUrl);
    }
}